<?php
namespace app\index\controller;

use think\Db;
use think\Request;

class Notice
{
    public function uploadPptFileNotice()
    {
        $input = Request()->param();

        file_put_contents(RUNTIME_PATH . 'test_notice.txt', json_encode($input, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);

        $status = $input['status'];
        $course_id = $input['courseId'];
        $file_index = $input['fileIndex'];
        $msg = $input['msg'];

        if($status == 1){
            file_put_contents(RUNTIME_PATH . 'notice.txt', $course_id . '----' . $file_index . '-----time：' . date('Y-m-d H:i:s') . PHP_EOL, FILE_APPEND);

            if ($file_index && $course_id) {
                $data = [
                    'ppt_file_index' => $file_index,
                    'ppt_upload_status' => 1,
                    'ppt_upload_error_msg' => ''
                ];
                Db::name('course')->where(['id' => $course_id])->update($data);
            }
        }else{
            file_put_contents(RUNTIME_PATH . 'notice_error.txt', $course_id . '----' . $msg . '-----time：' . date('Y-m-d H:i:s') . PHP_EOL, FILE_APPEND);

            if ($course_id) {
                $data = [
                    'ppt_upload_status' => -1,
                    'ppt_upload_error_msg' => $msg
                ];
                Db::name('course')->where(['id' => $course_id])->update($data);
            }
        }

    }
}